import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

/**
 * Part of the wizard mode steps. Prompts the user as
 * top whether they want a keyword index in the final report.
 * 
 * @author James Stanier
 */
public class KeywordGUI implements ActionListener {
	
	InDepthGUI wiz2;
	
	String outputFileName;
	String outputDir;
	String paperType;
	int fontSize;
	boolean twoSidedPrinting;
	boolean inDepthSection;
	boolean keywordIndex;
	
	JFrame window;
	JFrame prev;
	JButton nextButton;
	JButton backButton;
	JCheckBox keywordButton;
	
	ArrayList<File> inputFiles;
	
	/**
	 * Constructor.
	 * @param g The previous window; InDepthGUI.
	 */
	public KeywordGUI(InDepthGUI g) {
		wiz2 = g;
		inputFiles = wiz2.getInputFiles();
		prev = wiz2.getWindow();
		outputFileName = wiz2.getOutputFileName();
		outputDir = wiz2.getOutputDir();
		paperType = wiz2.getPaperType();
		fontSize = wiz2.getFontSize();
		twoSidedPrinting = wiz2.isTwoSidedPrinting();
		inDepthSection = wiz2.isInDepthSection();
		keywordIndex = false;
		keywordWindow();
	}
	
	/**
	 * Configures and draws the screen.
	 */
	public void keywordWindow() {
		window = new JFrame("JavaLiN - Wizard mode");
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.setSize(350,500);
		window.setLocationRelativeTo(null);
		window.toFront();
		window.setResizable(false);
		
		// Introductory passage and logo
		JPanel top = new JPanel();
		top.setLayout(new BorderLayout());
		top.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
		
		// Logo
		JLabel logo = new JLabel();
		logo.setIcon(new ImageIcon("logo.png"));
		logo.setHorizontalAlignment(JLabel.CENTER);
		top.add(logo, BorderLayout.NORTH);
		
		// Heading information
		JPanel progress = new JPanel();
		JPanel header = new JPanel();
		progress.setLayout(new BorderLayout());
		header.setLayout(new BorderLayout());
		JLabel backwards = new JLabel("<HTML><font size=2>&#171; In-depth commenting</HTML>");
		progress.add(backwards, BorderLayout.WEST);
		JLabel forwards = new JLabel("<HTML><font size=2> Variable output &#187;</HTML>");
		progress.add(forwards, BorderLayout.EAST);
		JLabel heading = new JLabel("<HTML><b><font size=5>3. Keyword index</b></HTML>");
		heading.setHorizontalAlignment(JLabel.CENTER);
		heading.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
		header.add(heading, BorderLayout.CENTER);
		JLabel description = new JLabel("<HTML><font size=3>If you marked keywords in your Javalin " +
				"comments, then tick the box to create an index of these for easy reference. If you " +
				"haven't used Javalin comments at all, then leave this blank.</HTML>");
		description.setBorder(BorderFactory.createEmptyBorder(20,10,10,10));
		header.add(description, BorderLayout.SOUTH);
		top.add(progress, BorderLayout.CENTER);
		top.add(header, BorderLayout.SOUTH);
		
		// Check box
		JPanel keywordPanel = new JPanel();
		keywordPanel.setBorder(BorderFactory.createEmptyBorder(10,0,0,10));
		keywordButton = new JCheckBox("Keyword index");
		keywordButton.addActionListener(this);
		keywordButton.setToolTipText("Create an index for marked-up keywords.");
		keywordPanel.add(keywordButton);
		
		// Navigation buttons
		JPanel navButtons = new JPanel();
		navButtons.setLayout(new BorderLayout());
		navButtons.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
		backButton = new JButton("<< Back");
		backButton.addActionListener(this);
		navButtons.add(backButton, BorderLayout.WEST);
		nextButton = new JButton("Next >>");
		nextButton.addActionListener(this);
		navButtons.add(nextButton, BorderLayout.EAST);
		
		window.add("North",top);
		window.add("Center",keywordPanel);
		window.add("South",navButtons);
		window.validate();
		window.setVisible(true);
	}
	
	/**
	 * Events occurring on component interaction.
	 */
	public void actionPerformed(ActionEvent e) {
		Object x = e.getSource();
		if(x.equals(keywordButton)) {
			keywordIndex = keywordButton.isSelected();
		}
		else if(x.equals(backButton)) {
			clearSettings();
			window.setVisible(false);
			prev.setVisible(true);
		}
		else if(x.equals(nextButton)) {
			window.setVisible(false);
			VariableGUI vgui = new VariableGUI(this);
		}
	}
	
	/**
	 * Clear the settings of this screen.
	 */
	public void clearSettings() {
		keywordIndex = false;
	}
	
	/**
	 * Get the current font size.
	 * @return The font size as an integer.
	 */
	public int getFontSize() {
		return fontSize;
	}
	
	/**
	 * Get the current paper type.
	 * @return The paper type as a String.
	 */
	public String getPaperType() {
		return paperType;
	}
	
	/**
	 * Get current two-sided printing status.
	 * @return Whether two-sided printing is enabled.
	 */
	public boolean isTwoSidedPrinting() {
		return twoSidedPrinting;
	}
	
	/**
	 * Get the current window.
	 * @return The current JFrame window.
	 */
	public JFrame getWindow() {
		return window;
	}
	
	/**
	 * Get the current output directory.
	 * @return The output directory as a String.
	 */
	public String getOutputDir() {
		return outputDir;
	}
	
	/**
	 * Get the output file name.
	 * @return The output file name as a String.
	 */
	public String getOutputFileName() {
		return outputFileName;
	}
	
	/**
	 * Get whether an in-depth section has been requested.
	 * @return Whether there will be an in-depth section as a boolean.
	 */
	public boolean isInDepthSection() {
		return inDepthSection;
	}
	
	/**
	 * Get whether a keyword index has been requested.
	 * @return Whether there will be a keyword index as a boolean.
	 */
	public boolean isKeywordIndex() {
		return keywordIndex;
	}
	
	/**
	 * Get the input source file references.
	 * @return Input source files as File objects.
	 */
	public ArrayList<File> getInputFiles() {
		return inputFiles;
	}
}
